package com.ly.gof.structure.composite.safe;

import java.util.ArrayList;

/**
 * @author liuyang
 * @des
 * @Version 1.0
 * @Date: 28/07/2021 16:28
 */
public class CompositeSafe implements ComponentSafe {
    private ArrayList<ComponentSafe> children = new ArrayList<ComponentSafe>();

    public void add(ComponentSafe c) {
        children.add(c);
    }

    public void remove(ComponentSafe c) {
        children.remove(c);
    }

    public ComponentSafe getChild(int i) {
        return children.get(i);
    }

    public void operation() {
        for (Object obj : children) {
            ((ComponentSafe)obj).operation();
        }
    }
}
